﻿using System;
using System.Runtime.InteropServices;

public class Node<T>
{
    public Node<T> Next { get; set; }
    public T Data { get; set; }
    public Node(T t)
    {
        Next = null;
        Data = t;
    }
}
public class GenericList<T>
{
    private Node<T> head;
    private Node<T> tail;
    public GenericList()
    {
        tail = head = null;
    }
    public Node<T> Head
    {
        get=>head;
    }
    public void Add(T t)
    {
        Node<T> n = new Node<T>(t);
        if (tail == null)
        {
            head = tail = n;
        }
        else
        {
            tail.Next = n;
            tail = n;
        }
    }
    public void ForEach(Action<T> action)
    {
        Node<T> current = head;
        while (current != null)
        {
            action(current.Data);
            current = current.Next;
        }
    }

}
public class main{
    public static void Main(string[] args)
    {
        
        GenericList<int> list = new GenericList<int>();
        for(int i = 0; i < 10; i++) {
            list.Add(i);
        }
        list.ForEach(Console.WriteLine);
        int max = int.MinValue;
        list.ForEach(s => max = (max > s ? max : s));
        Console.WriteLine("最大值为："+max);
        //最小值
        int min = int.MaxValue;
        list.ForEach(s => min = (min < s ? min : s));
        Console.WriteLine("最小值为："+min);

        //求和
        int sum = 0;
        list.ForEach(s => sum += s); 
        Console.WriteLine("求和"+sum);
        

    }
}